

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pleasure_video/constant/color.dart';
import 'package:flutter_pleasure_video/constant/style.dart';
import 'package:flutter_pleasure_video/route/router.dart';
import 'package:flutter_pleasure_video/util/screen_util.dart';
import 'package:flutter_pleasure_video/widget/common/Image_widget.dart';
import 'package:get/get.dart';
import 'package:flutter_pleasure_video/util/extensions/string_extensions.dart';

class BackstageHome extends StatelessWidget {
  final String imageUrl="http://pic.aimymusic.com/ifapp/10009664/Gau7yOQ4OmZRzs7bYWhQqw==.png";


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: null,
      body: Container(
        child: Column(
          children: [
            _topUserInformationUi(),
            _getSettingIcon(),
          ],
        ),
      ),
    );
  }


  Widget _topUserInformationUi(){
    return UnconstrainedBox(
      child: Container(
        color: AppColor.mainBlue,
        width: Get.width,
        padding: EdgeInsets.only(top: 70+ScreenUtil.instance.statusBarHeight,bottom: 60,left: 40),
        child: Row(
          children: [
            ImageWidget.network(imageUrl,isCircle: true,diameter: 66),
            SizedBox(width: 16),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("名字",style: AppStyle.textMedium18),
                SizedBox(height: 16),
                Text("subtitle"),
              ],
            ),
          ],
        ),
      ),
    );
  }



  Widget _getSettingIcon(){
    return Expanded(
      child: SizedBox(
        child: CustomScrollView(
          slivers: <Widget>[
            SliverToBoxAdapter(child: SizedBox(height: 30)),
            _getSliverGrid(),
          ],
        ),
      ),
    );
  }


  Widget _getSliverGrid(){
    return SliverGrid.count(crossAxisCount: 3,
        childAspectRatio: 1.2,
        mainAxisSpacing: 1,
        crossAxisSpacing: 1,
        children: [
          _getItem("扫码添加"),
          _getItem("添加资源"),
          _getItem("我的资源"),
          _getItem("全部资源"),
          _getItem("我的收藏"),
          _getItem("我的数据"),
          _getItem("我的消息"),
        ],
    );
  }


  Widget _getItem(String title){
    return GestureDetector(
      onTap: ()=>_onItemClickListener(title),
      child: Container(
        color: AppColor.transparent,
        child: Column(
          children: [
            ImageWidget.network(imageUrl,diameter: 45),
            SizedBox(height: 8),
            Text(title,style: AppStyle.textMedium18),
          ],
        ),
      ),
    );
  }

  void _onItemClickListener(String title){
    switch (title) {
      case "我的资源":
        "我的资源".print;
        break;
      case "全部资源":
        "全部资源".print;
        break;
      case "我的消息":
        "我的消息".print;
        break;
      case "添加资源":
        AppRouter.toAddSourcePage();
        break;
      case "我的数据":
        "我的数据".print;
        break;
      case "我的收藏":
        "我的收藏".print;
        break;
      case "扫码添加":
        AppRouter.toYckSourceListPage();
        break;
    }
  }


}
